package com.smart.manager.member.repository;

import cn.hutool.core.lang.Opt;
import com.smart.common.entities.core.Page;
import com.smart.manager.member.entities.bodys.RMemberPigSale;
import com.smart.manager.member.entities.models.MemberPigSale;
import com.smart.manager.member.entities.models.MemberPigSale;
import com.smart.manager.member.entities.models.query.QMemberPigSale;
import com.smart.manager.product.entities.enums.PigStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 售卖表
 *
 * @author leo
 * @date 2023/09/22
 */
@Service
@Log4j2
@RequiredArgsConstructor
public class MemberPigSaleRepository {


    public Page<MemberPigSale> pageList(RMemberPigSale.SearchBody search) {
        QMemberPigSale query = new QMemberPigSale();
        Opt.ofBlankAble(search.getBuyerId()).ifPresent(x -> query.buyerId.eq(x));
        Opt.ofBlankAble(search.getPigId().getCode()).ifPresent(x -> query.pigId.code.contains(x));
        query.order().id.desc();
        query.setFirstRow(search.firstRow()).setMaxRows(search.maxRows());
        return new Page<MemberPigSale>().load(query.findPagedList());
    }

}
